package com.sensor.work.config;

import com.baomidou.mybatisplus.extension.api.R;
import com.sensor.work.entity.ClimaticExtremum;
import com.sensor.work.entity.Threshold;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;



@Slf4j
public   class   ClimaticExtremumConfig {
    private static  Map<Integer, Map<String,ClimaticExtremum>> map = new HashMap<>();

//    public static Map<Integer, Map<String, Float>> getMap() {
//        return map;
//    }

    //    private static List<ClimaticExtremum> list = new ArrayList<>();

    static {
        // 1月份
        map.put(1,new HashMap<String, ClimaticExtremum>(){{
                        put("AGAa_A", new ClimaticExtremum(1045F,"Max"));
                        put("AGAc_A",new ClimaticExtremum(1005F,"Min"));
                        put("AAAa_A",new ClimaticExtremum(24.5F,"Max"));
                        put("AAAc_A",new ClimaticExtremum(-9.6F,"Min"));
                        put("ADB_A",new ClimaticExtremum(30F,"Max"));
                        put("ADB_A",new ClimaticExtremum(-30F,"Min"));
                        put("AHB_1_A",new ClimaticExtremum(50F,"Max"));
                        put("AFDa_A",new ClimaticExtremum(17F,"Max"));
                        put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

                        //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
                        //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
                        //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
                        //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});

        map.put(2,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1041.8F,"Max"));
            put("AGAc_A",new ClimaticExtremum(998.8F,"Min"));
            put("AAAa_A",new ClimaticExtremum(28F,"Max"));
            put("AAAc_A",new ClimaticExtremum(-9.5F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(50F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(45,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-3.9,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});


        map.put(3,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1033.7F,"Max"));
            put("AGAc_A",new ClimaticExtremum(1001.5F,"Min"));
            put("AAAa_A",new ClimaticExtremum(33F,"Max"));
            put("AAAc_A",new ClimaticExtremum(-4F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(50F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(50,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-3.6,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});




        map.put(4,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1030.9F,"Max"));
            put("AGAc_A",new ClimaticExtremum(995.8F,"Min"));
            put("AAAa_A",new ClimaticExtremum(35F,"Max"));
            put("AAAc_A",new ClimaticExtremum(0.4F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(50F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});




        map.put(5,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1024F,"Max"));
            put("AGAc_A",new ClimaticExtremum(996.9F,"Min"));
            put("AAAa_A",new ClimaticExtremum(37F,"Max"));
            put("AAAc_A",new ClimaticExtremum(6.8F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(100F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});




        map.put(6,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1017.2F,"Max"));
            put("AGAc_A",new ClimaticExtremum(993.2F,"Min"));
            put("AAAa_A",new ClimaticExtremum(39F,"Max"));
            put("AAAc_A",new ClimaticExtremum(12.6F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(100F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});




        map.put(7,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1013.5F,"Max"));
            put("AGAc_A",new ClimaticExtremum(980F,"Min"));
            put("AAAa_A",new ClimaticExtremum(41F,"Max"));
            put("AAAc_A",new ClimaticExtremum(16.4F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(100F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});



        map.put(8,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1016.8F,"Max"));
            put("AGAc_A",new ClimaticExtremum(980F,"Min"));
            put("AAAa_A",new ClimaticExtremum(41F,"Max"));
            put("AAAc_A",new ClimaticExtremum(18.6F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(100F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});




        map.put(9,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1025F,"Max"));
            put("AGAc_A",new ClimaticExtremum(980F,"Min"));
            put("AAAa_A",new ClimaticExtremum(39F,"Max"));
            put("AAAc_A",new ClimaticExtremum(10.1F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(100F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});



        map.put(10,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1032F,"Max"));
            put("AGAc_A",new ClimaticExtremum(999F,"Min"));
            put("AAAa_A",new ClimaticExtremum(36.5F,"Max"));
            put("AAAc_A",new ClimaticExtremum(2.6F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(40F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
        }});



        map.put(11,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1041.8F,"Max"));
            put("AGAc_A",new ClimaticExtremum(998.8F,"Min"));
            put("AAAa_A",new ClimaticExtremum(28F,"Max"));
            put("AAAc_A",new ClimaticExtremum(-9.5F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(30F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(40,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-30,"Min"));
        }});



        map.put(12,new HashMap<String, ClimaticExtremum>(){{
            put("AGAa_A", new ClimaticExtremum(1045F,"Max"));
            put("AGAc_A",new ClimaticExtremum(1008.8F,"Min"));
            put("AAAa_A",new ClimaticExtremum(25F,"Max"));
            put("AAAc_A",new ClimaticExtremum(-9.4F,"Min"));
            put("ADB_A",new ClimaticExtremum(30F,"Max"));
            put("ADB_A",new ClimaticExtremum(-30F,"Min"));
            put("AHB_1_A",new ClimaticExtremum(30F,"Max"));
            put("AFDa_A",new ClimaticExtremum(17F,"Max"));
            put("AFAe_A",new ClimaticExtremum(23.8F,"Max"));

            //put("地面温度气候极限最高值",new ClimaticExtremum(45,"Max"));
            //put("地面温度气候极限最低值",new ClimaticExtremum(-10,"Min"));
            //put("草面温度气候极限最高值",new ClimaticExtremum(80,"Max"));
            //put("草面温度气候极限最低值",new ClimaticExtremum(-30,"Min"));
        }});




    }




    /**
     *  是否超过极限值
     * @param value 值
     * @param arg 参数
     * @return 超过了 false  未超过 ture
     */
    public static boolean isExceed(Float value,String arg, Integer day){
        Map<String, ClimaticExtremum> stringClimaticExtremumMap = map.get(day);
        ClimaticExtremum climaticExtremum = stringClimaticExtremumMap.get(arg);
        if (climaticExtremum==null){
//            log.error("配置中没有的字段---#{}---进行了比较",arg);
            return true;
        }

        if (climaticExtremum.getSymbol().equals("Max")){


            return ! ( value> climaticExtremum.getValue());
        }
        if (climaticExtremum.getSymbol().equals("Min")){


            return ! (value< climaticExtremum.getValue());
        }


        return true;
    }
}
